package com.aijk.ehm.service;

import com.aijk.base.entity.PagingRequest;
import com.aijk.commons.utils.Utils;

import com.aijk.ehm.dao.mybatis.EhmProblemRecordMapper;
import com.aijk.ehm.model.EhmProblemRecord;
import com.aijk.ehm.model.EhmProblemRecordExample;
import com.aijk.ehm.model.qo.EhmProblemRecordQo;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class EhmProblemRecordService {
    private static Logger logger = LoggerFactory.getLogger(EhmProblemRecordService.class);

    @Autowired
    private EhmProblemRecordMapper mapper;

    public EhmProblemRecordExample getExample(EhmProblemRecordQo qo) {
        EhmProblemRecordExample example = new EhmProblemRecordExample();
        EhmProblemRecordExample.Criteria criteria = example.createCriteria();
        if (qo != null) {
            if (Utils.isNotEmpty(qo.getSortway())) example.setOrderByClause(qo.getSortway());
            if(qo.getInPid()!=null && qo.getInPid().size() > 0) criteria.andPidIn(qo.getInPid());
            if(Utils.isNotEmpty(qo.getRid())) criteria.andRidEqualTo(qo.getRid());
            if(Utils.isNotEmpty(qo.getCompanyId())) criteria.andCompanyIdEqualTo(qo.getCompanyId());
        }
        return example;
    }

    public int count(EhmProblemRecordQo qo) {
        return mapper.countByExample(getExample(qo));
    }

    public int save(EhmProblemRecord bean) {
        return mapper.insertSelective(bean);
    }

    public int delete(Long id) {
        return mapper.deleteByPrimaryKey(id);
    }

    public int update(EhmProblemRecord bean) {
        return mapper.updateByPrimaryKeySelective(bean);
    }

    public EhmProblemRecord findOne(Long id) {
        return mapper.selectByPrimaryKey(id);
    }

    public List<EhmProblemRecord> find(EhmProblemRecordQo qo) {
        return mapper.selectByExample(getExample(qo));
    }

    public PageInfo<EhmProblemRecord> page(PagingRequest pagingRequest, EhmProblemRecordQo qo) {
        PageHelper.startPage(pagingRequest.getPageNum() , pagingRequest.getPageSize());
        return new PageInfo<EhmProblemRecord>(mapper.selectByExample(getExample(qo)));
    }
}